package com.jprocms.module.cms.controller.admin.license;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.jpro.framework.common.pojo.CommonResult;
import com.jprocms.module.cms.controller.admin.license.vo.LicenseVO;
import com.jprocms.module.cms.util.EnvUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.security.PermitAll;

import static com.jpro.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 授权信息")
@RestController
@RequestMapping("/cms/license")
@Validated
public class LicenseController {

    @GetMapping("/get")
    @Operation(summary = "获取授权信息")
    @PermitAll
    public CommonResult<LicenseVO> getLicense() {
        LicenseVO vo = new LicenseVO();
        vo.setAppid(System.getProperty("appId"));
        vo.setProductName(System.getProperty("productName"));
        vo.setProject(System.getProperty("project"));
        vo.setVersion(System.getProperty("version"));
        int productGrade = EnvUtil.getGrade();
        vo.setProductGrade(productGrade);
        vo.setMacAddress(System.getProperty("macAddress"));
        final String expiration = System.getProperty("expiration");
        vo.setExpiration(LocalDateTimeUtil.parse(expiration, "yyyy-MM-dd"));
        return success(vo);
    }

}
